fix: destroy socket on SOCKS5 negotiation timeout - #5706
Open
mcollina wants to merge 1 commit into
Open
Conversation
Socks5ProxyAgent's createSocks5Connection() rejected its promises on the auth and CONNECT timeouts without destroying the underlying socket. Because the socket was never handed to the per-origin Pool, agent.close()/destroy() could not reach it and it leaked open for the process lifetime. Destroy the socket in both timeout paths before rejecting.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5706 +/- ##
==========================================
+ Coverage 93.43% 93.47% +0.03%
==========================================
Files 110 110
Lines 38733 38894 +161
==========================================
+ Hits 36190 36355 +165
+ Misses 2543 2539 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5704
Socks5ProxyAgent'screateSocks5Connection()rejected its promises on the SOCKS5 auth and CONNECT negotiation timeouts without destroying the underlying socket. Because the socket is never handed to the per-originPool(theconnectcallback that would register it is never reached), it's completely untracked —agent.close()/agent.destroy()only iteratethis[kPools], so neither can reach it. A proxy that accepts the TCP connection but stalls during negotiation leaks one open socket per attempt for the lifetime of the process.This calls
socks5Client.destroy()in both timeout paths before rejecting, tearing down the socket (matching the cleanup already done on theerrorpath).A regression test spins up a proxy that accepts the connection, drains the SOCKS5 greeting, but never replies, then verifies the proxy-side socket is destroyed after the request rejects and
agent.close()resolves.